package com.example.ac;

import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.example.ac.util.MyUtil;
import com.example.ac.util.SoundPool;

public class BuddhaActivity extends AppCompatActivity implements View.OnClickListener {
    ImageButton cog;


    String value = "功德 + 1";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_buddha);
        cog = findViewById(R.id.cog);
        cog.setOnClickListener(this);//添加点击事件
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
//        SoundPool soundPool = null;
        int action = event.getAction();
        if (action == MotionEvent.ACTION_DOWN)
            Disp();
//        soundPool.play(1);
        return super.onTouchEvent(event);
    }

    private void Disp() {
        String msg = String.valueOf(value);
        SpannableStringBuilder builder = new SpannableStringBuilder(msg);
        AbsoluteSizeSpan sizeSpan = new AbsoluteSizeSpan(100);
        ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.parseColor("#FFFFFFFF"));
        builder.setSpan(sizeSpan, 0, msg.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.setSpan(colorSpan, 0, msg.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        Toast toast = Toast.makeText(BuddhaActivity.this, builder, Toast.LENGTH_SHORT);
        LinearLayout layout = (LinearLayout) toast.getView();
        //设置背景
        layout.setBackgroundResource(R.color.black);
        toast.setGravity(Gravity.CENTER, 0, -500);
        MyUtil.showMyToast(toast, 50);
    }


    @Override
    public void onClick(View view) {
        AlertDialog.Builder buddha = new AlertDialog.Builder(this);
        if (view == cog) {
            LinearLayout revise = (LinearLayout) getLayoutInflater().inflate(R.layout.cogs, null);
            buddha.setTitle("进行自定义设置").setView(revise);
            buddha.setPositiveButton("确定", new loginClick());
            buddha.setNegativeButton("退出", new exitClick());
            buddha.create();
            buddha.show();
        }
    }

//    private class okClick implements DialogInterface.OnClickListener {
//        @Override
//        public void onClick(DialogInterface dialogInterface, int i) {
//            dialogInterface.cancel();
//        }
//    }

    private class loginClick implements DialogInterface.OnClickListener {
        EditText news;
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            news = (EditText)findViewById(R.id.news);
            if (news.getText().toString().equals("a")) {
//                value = news.getText().toString();
//                System.out.println(value);
                Toast toast = Toast.makeText(BuddhaActivity.this, "修改成功", Toast.LENGTH_SHORT);
                MyUtil.showMyToast(toast, 40);
            } else {
                dialogInterface.dismiss();
            }
        }
    }

    private class exitClick implements DialogInterface.OnClickListener {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {

        }
    }
}